package org.andes.help.struct;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import lisp.SExp;

/**
 * Created by IntelliJ IDEA. User: wenfeix Date: 2011-2-1 Time: 10:41:24 To
 * change this template use File | Settings | File Templates.
 */
public class PsmGraph {
	List<PsmNode> psmNodes = new ArrayList<PsmNode>();

	public void readContent(InputStream S) throws Exception {
		SExp sexp = SExp.INPUT(S);
		List<SExp> nodeList = sexp.toList();
		for (SExp node : nodeList) {
			List<SExp> elemList = node.toList();
			String nodeType = elemList.get(0).GetValue();
			System.out.println(nodeType);
			if(nodeType!=null){
				PsmNode pn = readNode(nodeType, node);
				psmNodes.add(pn);
			}
			

		}
	}

	private PsmNode readNode(String nodeType, SExp sexp) {
		
		if (nodeType.equals("DO")) {
			//List<SExp> elemList = sexp.toList();
			DoNode node=new DoNode();
			node.readContent(sexp);
			return node;			
		}else if (nodeType.equals("SG")) {
			//List<SExp> elemList = sexp.toList();
			SGNode node=new SGNode();
			node.readContent(sexp);
			return node;			
		}else if (nodeType.equals("OP")) {
			//List<SExp> elemList = sexp.toList();
			OpNode node=new OpNode();
			node.readContent(sexp);
			return node;			
		}
		PsmNode pn = new PsmNode();
		pn.setType(nodeType);
		return pn;

	}

	public List<PsmNode> getPsmNodes() {
		return psmNodes;
	}
	public void buildTree(){
		
	}

}
